import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Test {
    public static void main(String[] args) throws ClassNotFoundException {
        Class.forName(Test.class.getName());
        ClassLoader.getSystemClassLoader().loadClass(Test.class.getName());

        CharSequence c = "";
        Character ch = 'a';
        ExecutorService service = Executors.newCachedThreadPool();
        ConcurrentHashMap<String, String> hashMap = new ConcurrentHashMap<>();

        StringBuffer buffer = new StringBuffer();
        buffer.append("");
        StringBuilder builder = new StringBuilder();
        builder.append("");

        ArrayList<Integer> list = new ArrayList<>(100);
        list.add(1);

        HashMap<String, String> map = new HashMap<>();
        map.put("", "");
        map.get("");

        String s = "abs";

        printValue(11);

        HashMap<String, String> map1 = new HashMap<>();
        LinkedHashMap<String, String> map2 = new LinkedHashMap<>();
        map2.put("", "");
        map1.put("", "");
    }

    /**
     * 泛型方法
     *
     * @param data
     * @param <T>
     */
    public <T> T setData(T data) {
        T d = data;
        return d;
    }

    /**
     * 寻找链表的倒数第n个值
     */
    static class Node<T> {
        T value;

        Node<T> next;

        public Node(T value) {
            this.value = value;
        }
    }

    static void printValue(int index) {
        Node<Integer> header = null;
        Node<Integer> endNode = null;

        Node<Integer> tempNode;

        for (int i = 0; i < 10; i++) {
            if (header == null) {
                header = new Node<>(i);
                endNode = header;
            } else {
                tempNode = new Node<>(i);
                endNode.next = tempNode;
                endNode = tempNode;
                tempNode = null;
            }
        }

        Node<Integer> node1 = header;
        Node<Integer> node2 = header;
        int i = 0;
        do {
            if (i < index) {
                i++;
            } else {
                node2 = node2.next;
            }
//            print(node.value);
        } while ((node1 = node1.next) != null);
        print(node2.value);
    }

    /**
     * 二分查找
     */
    static int[] datas = new int[]{1, 3, 5, 8, 12, 16, 20, 30};

    static int start = 0;
    static int end = datas.length - 1;

    public static void get(int data) {

        int mid = (end - start) / 2;

        if (datas[mid] == data) {
            print(mid);
        } else if (data < datas[mid]) {
            end = mid;
            get(data);
        } else if (data > datas[mid]) {
            start = mid;
            get(data);
        }

    }

    public static void print(int value) {
        System.out.println("打印的值:" + value);
    }
}

